
const {
  create,
  getMomentDetail,
  getServicesList,
  updateServicesMonent,
  removeServicesMonent
} = require("../services/momentServices")
class MomentController {
  async create(req, res, next) {

    // console.log(req.user.id, req.body)
    const userId = req.user.id;
    const content = req.body.content;
    const result = await create(userId, content)
    // res.send("用户发表动态成功")
    res.json({
      msg: result
    })
  }

  // 获取某一条动态的详情
  async detail(req, res, next) {
    console.log(req.query.id, "评论id");

    // 去数据库查数据
    const [result] = await getMomentDetail(req.query.id); // 返回的是一个数组
    res.json({
      msg: result
    })
  }

  // 获取评论列表List
  async getList(req, res, next) {
    console.log(req.query.limit, req.query.total, "列表")
    const result = await getServicesList(req.query.limit, req.query.total);
    res.json(result)
  }


  async update(req, res, next) {

    const result = await updateServicesMonent(req.body.moment_id, req.body.content)
    console.log("修改接口", result);
    res.json({
      msg: "更新成功"
    })

  }
  // 删除某条评论接口
  async remove(req, res, next) {
    const result = await removeServicesMonent(req.body.moment_id);
    console.log("删除评论", result)
    res.json({
      msg: "删除成功"
    })
  }
}

module.exports = new MomentController()